package cn.kgc.controller;

import cn.kgc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;


@Controller
public class UserController {
//    @RequestMapping("/login")
//    public @ResponseBody Dto login(String userName, String userPwd){
//        //省略验证步骤  dto    -----dode user success
//        return dto;
//    }



    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public String regedit(User user, @RequestParam("photos") MultipartFile[]  mpf, HttpServletRequest request){
        String path=request.getServletContext().getRealPath("/upload");
        String fileName=null;
        for (MultipartFile mf:mpf) {
            fileName=mf.getOriginalFilename();
            File file=new File(path + File.separator + UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf(".")));
            try {
                mf.transferTo(file);
            } catch (IOException e) {
            }
            if (!file.exists()){
                file.mkdirs();
            }
        }
        return "main";
    }




}